package com.ruoyi.web.controller.system;

import java.util.List;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ArNoPolicy;
import com.ruoyi.system.service.IArNoPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 档号规则信息Controller
 *
 * @author ruoyi_ln
 * @date 2022-03-01
 */
@RestController
@RequestMapping("/system/nopolicy")
public class ArNoPolicyController extends BaseController
{
    @Autowired
    private IArNoPolicyService arNoPolicyService;

    /**
     * 查询档号规则信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:list')")
    @ApiOperation("查询档号规则信息列表")
    @GetMapping("/list")
    public TableDataInfo list(ArNoPolicy arNoPolicy)
    {
        startPage();
        List<ArNoPolicy> list = arNoPolicyService.selectArNoPolicyList(arNoPolicy);
        return getDataTable(list);
    }

    /**
     * 导出档号规则信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:export')")
    @Log(title = "档号规则信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ArNoPolicy arNoPolicy)
    {
        List<ArNoPolicy> list = arNoPolicyService.selectArNoPolicyList(arNoPolicy);
        ExcelUtil<ArNoPolicy> util = new ExcelUtil<ArNoPolicy>(ArNoPolicy.class);
        return util.exportExcel(list, "ar_no_policy");
    }

    /**
     * 获取档号规则信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:query')")
    @ApiOperation("获取档号规则信息详细信息")
    @ApiImplicitParam(name = "recNo", value = "档号规则编号", required = true, dataType = "String", paramType = "传档号规则编号")
    @GetMapping(value = "/{recNo}")
    public AjaxResult getInfo(@PathVariable("recNo") String recNo)
    {
        return AjaxResult.success(arNoPolicyService.selectArNoPolicyById(recNo));
    }

    /**
     * 新增档号规则信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:add')")
    @Log(title = "档号规则信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增档号规则信息")
    @ApiImplicitParam(name = "arNoPolicy", value = "档号规则对象", required = true, dataType = "ArNoPolicy", paramType = "传档号规则对象")
    @PostMapping
    public AjaxResult add(@RequestBody ArNoPolicy arNoPolicy)
    {
        return arNoPolicyService.insertArNoPolicy(arNoPolicy);
    }

    /**
     * 修改档号规则信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:edit')")
    @Log(title = "档号规则信息", businessType = BusinessType.UPDATE)
    @ApiOperation("修改档号规则信息")
    @ApiImplicitParam(name = "arNoPolicy", value = "档号规则对象", required = true, dataType = "ArNoPolicy", paramType = "传档号规则对象")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody ArNoPolicy arNoPolicy)
    {
        return arNoPolicyService.updateArNoPolicy(arNoPolicy);
    }

    /**
     * 删除档号规则信息
     */
    @PreAuthorize("@ss.hasPermi('system:ar_no_policy:remove')")
    @Log(title = "档号规则信息", businessType = BusinessType.DELETE)
    @ApiOperation("删除档号规则信息")
    @ApiImplicitParam(name = "recNos", value = "档号规则编号数组", required = true, dataType = "String[]", paramType = "传档号规则编号数组")
    @GetMapping("/remove/{recNos}")
    public AjaxResult remove(@PathVariable String[] recNos)
    {
        return arNoPolicyService.deleteArNoPolicyByIds(recNos);
    }
}
